﻿using Ninject;
using Ninject.Modules;

namespace Jimmy.NinjiectDemo.Service
{
    internal class KernelBuilder
    {
        public static IKernel Kernel
        {
            get;
            private set;
        }

        private static bool initialized = false;

        public static void Build(NinjectModule module)
        {
            if (initialized)
            {
                return;
            }

            Kernel = new StandardKernel(module);
        }

        public static void Build(IKernel kernel)
        {
            if (initialized)
            {
                return;
            }
            Kernel = kernel;
        }

        public static void UnBuild()
        {
            if (null != Kernel)
            {
                Kernel.Dispose();
                Kernel = null;
            }
        }
    }
}